USE SAS
GO

IF EXISTS (SELECT 1 from sysobjects where xtype = 'FN' AND NAME = 'GetActivityTypeXml')
	DROP FUNCTION dbo.GetActivityTypeXml
GO


CREATE FUNCTION dbo.GetActivityTypeXml() 
RETURNS VARCHAR(MAX)
AS
BEGIN
	
	declare 
		@result			varchar(max)

	SET @result = '<ACTIVITYTYPE><entry id="0"></entry>'

	select @result = @result + '<entry id="' + CAST([ActivityType] AS VARCHAR) + '"><![CDATA[' +  TypeDesc + ']]></entry>'
	FROM TR_ACTIVITYTYPE 
	Order by TypeDesc
	
	SET @result = @result + '</ACTIVITYTYPE>'

	return @result

END


-- SELECT dbo.GetActivityTypeXml()
